package com.foxzzz.datamemory.util;

/**
 * @Author wujie
 * @Class SnowflakeUtil
 * @Description
 * @Date 2020/5/25 14:35
 */
public class SnowflakeUtil {

    private static SnowflakeIdWorker worker = null;


    public synchronized static void config(long workId, long dataCenterId) {
        if (workId > 32 || workId < 0) {
            throw new RuntimeException("WorkId 请设置在 0~31之间");
        }
        if (dataCenterId > 32 || dataCenterId < 0) {
            throw new RuntimeException("dataCenterId 请设置在 0~31之间");
        }
        worker = new SnowflakeIdWorker(dataCenterId, workId);
    }

    public static long getIdLong() {
        return worker.nextId();
    }

    public static String getIdString() {
        return String.valueOf(worker.nextId());
    }
}
